home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / src / mosmllib / test / filesys.sml < prev    next >
Encoding:
Text File  |  1997-08-18  |  6.1 KB  |  185 lines  |  [TEXT/R*ch]

  1. (* test/filesys.sml
  2.    PS 1995-03-23, 1996-05-01
  3. *)
  4.  
  5. (* DOS: Plain WRONG: test6a, test9a (and test9b);
  6.         Excusable:   test8b, test11b, test12a, test13a, test13b, test13c
  7.  *)
  8.  
  9. (* This requires two links to be present in the current directory:
  10.     testlink -> README
  11.     testcycl -> testcycl 
  12.     testbadl -> exists.not
  13.    Moreover, the file README must exist and the file exists.not not.
  14. *)
  15.  
  16.  
  17. use "auxil.sml";
  18.  
  19. local
  20.     open FileSys
  21.     (* Clean up: *)
  22.     val _ = (rmDir "testdir") handle OS.SysErr _ => (); 
  23.     val _ = (rmDir "testdir2") handle OS.SysErr _ => (); 
  24. in
  25.  
  26. val test1a = (mkDir "testdir" seq "OK") handle _ => "WRONG";
  27. val test1b = (mkDir "testdir" seq "WRONG")
  28.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  29.  
  30. val test2 = check'(fn _ => isDir "testdir");
  31.     
  32. val test3a = check'(fn _ => access("testdir", [A_READ, A_EXEC, A_WRITE]));
  33.  
  34. local 
  35.     val cdir = getDir();
  36. in
  37.     val test4a = (chDir cdir seq "OK") handle _ => "WRONG";
  38.     val test4b = check'(fn _ => cdir = getDir());
  39.     val _ = chDir "testdir";
  40.     val test4c = check'(fn _ => cdir <> getDir());
  41.     val _ = chDir "..";
  42.     val test4d = check'(fn _ => cdir = getDir());
  43. end;
  44.  
  45. val _ = rename{old = "testdir", new = "exists.not"};
  46.  
  47. val test5 = (rmDir "exists.not" seq "OK") handle _ => "WRONG";
  48.  
  49. val test6a = (openDir "exists.not" seq "WRONG") 
  50.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  51. val test6b = (isDir "exists.not" seq "WRONG")
  52.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  53. val test6c = (rmDir "exists.not" seq "WRONG")
  54.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  55. val test6d = (chDir "exists.not" seq "WRONG")
  56.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  57. val test6e = (fullPath "exists.not" seq "WRONG")
  58.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  59. val test6f = (realPath "exists.not" seq "WRONG")
  60.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  61. val test6g = (modTime "exists.not" seq "WRONG")
  62.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  63. val test6h = (setTime("exists.not", NONE) seq "WRONG")
  64.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  65. val test6i = (remove "exists.not" seq "WRONG")
  66.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  67. val test6j = (rename{old="exists.not", new="testdir2"} seq "WRONG")
  68.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  69. val test6k = (fileSize "exists.not" seq "WRONG")
  70.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  71. val test6l = check'(fn _ => not (access("exists.not", [])));
  72.  
  73. val _ = mkDir "testdir";
  74.  
  75. local 
  76.     val dstr = openDir "testdir";
  77. in
  78.     val test7a = 
  79.     check'(fn _ => "." = readDir dstr
  80.            andalso ".." = readDir dstr
  81.            andalso "" = readDir dstr);
  82.     val _ = rewindDir dstr;
  83.     val test7b = 
  84.     check'(fn _ => "." = readDir dstr
  85.            andalso ".." = readDir dstr
  86.            andalso "" = readDir dstr);
  87.     val _ = closeDir dstr;
  88.     val test7c = (readDir dstr seq "WRONG")
  89.               handle OS.SysErr _ => "OK" | _ => "WRONG";
  90.     val test7d = (rewindDir dstr seq "WRONG")
  91.               handle OS.SysErr _ => "OK" | _ => "WRONG";
  92.     val test7e = (closeDir dstr seq "OK")
  93.               handle _ => "WRONG"
  94. end
  95.  
  96. val test8a = 
  97.     check'(fn _ => fullPath "." = getDir ());
  98. val test8b = 
  99.     check'(fn _ => fullPath "testlink" = getDir() ^ "/README");
  100. val test8c = (fullPath "testcycl" seq "WRONG")
  101.           handle OS.SysErr _ => "OK" | _ => "WRONG";
  102. val test8d = (fullPath "testbadl" seq "WRONG")
  103.           handle OS.SysErr _ => "OK" | _ => "WRONG";
  104. val test8e = 
  105.     check'(fn _ => realPath "." = ".");
  106. val test8f = 
  107.     check'(fn _ => realPath "testlink" = "README");
  108. val test8g = (realPath "testcycl" seq "WRONG")
  109.           handle OS.SysErr _ => "OK" | _ => "WRONG";
  110. val test8h = (realPath "testbadl" seq "WRONG")
  111.           handle OS.SysErr _ => "OK" | _ => "WRONG";
  112.  
  113. val test9a = 
  114.     check'(fn _ => 
  115.        setTime ("README", SOME (Time.fromReal 1E6)) = ());
  116. val test9b = 
  117.     check'(fn _ => modTime "README" = Time.fromReal 1E6);
  118.     
  119. val test10a = (remove "testdir" seq "WRONG")
  120.               handle OS.SysErr _ => "OK" | _ => "WRONG";
  121. val test10b = 
  122.     check'(fn _ => 
  123.        rename{old = "testdir", new = "testdir2"} = ());
  124. val test10c = 
  125.     check'(fn _ => isDir "testdir2");
  126.  
  127. val test11a = 
  128.     check'(fn _ => not (access ("testdir", [])));
  129. val test11b = 
  130.     check'(fn _ => access("testlink", []));
  131. val test11c = 
  132.     check'(fn _ => not (access("testbadl", [])));
  133.  
  134. val test12a = 
  135.     check'(fn _ => isLink "testcycl" 
  136.        andalso isLink "testlink"
  137.        andalso isLink "testbadl");
  138. val test12b = 
  139.     check'(fn _ => not (isLink "testdir2"
  140.             orelse isLink "README"));
  141. val test12c = (isLink "exists.not" seq "WRONG")
  142.               handle OS.SysErr _ => "OK" | _ => "WRONG";
  143.  
  144. val test13a = 
  145.     check'(fn _ => readLink "testcycl" = "testcycl");
  146. val test13b = 
  147.     check'(fn _ => readLink "testlink" = "README");
  148. val test13c = 
  149.     check'(fn _ => readLink "testbadl" = "exists.not");
  150. val test13d = (readLink "testdir2" seq "WRONG")
  151.               handle OS.SysErr _ => "OK" | _ => "WRONG";
  152. val test13e = (readLink "exists.not" seq "WRONG")
  153.               handle OS.SysErr _ => "OK" | _ => "WRONG";
  154.  
  155. val test14 = (tmpName () seq "OK");
  156.  
  157. val test15a = 
  158.     check'(fn _ => 
  159.        fileId "." = fileId "."
  160.        andalso fileId "testlink" = fileId "README"
  161.         andalso fileId "." <> fileId "README");
  162. val test15b = 
  163.     check'(fn _ => compare(fileId ".", fileId ".") = EQUAL
  164.        andalso compare(fileId ".", fileId "README") <> EQUAL
  165.        andalso compare(fileId "testlink", fileId "README") = EQUAL
  166.        andalso (compare(fileId ".", fileId "README") = LESS 
  167.             andalso compare(fileId "README", fileId ".") = GREATER
  168.             orelse 
  169.             compare(fileId ".", fileId "README") = GREATER 
  170.             andalso compare(fileId "README", fileId ".") = LESS));
  171. val test15c = (fileId "exists.not" seq "WRONG")
  172.               handle OS.SysErr _ => "OK" | _ => "WRONG";
  173. val test15d = (fileId "testbadl" seq "WRONG")
  174.               handle OS.SysErr _ => "OK" | _ => "WRONG";
  175. val test15e = (fileId "testcycl" seq "WRONG")
  176.               handle OS.SysErr _ => "OK" | _ => "WRONG";
  177. (* Unix only: *)
  178. val test15f = 
  179.        check'(fn _ => 
  180.        fileId "hardlinkA" = fileId "hardlinkB"
  181.        andalso compare(fileId "hardlinkA", fileId "hardlinkB") = EQUAL);
  182.  
  183. val _ = rmDir "testdir2";
  184. end
  185.